package com.zhuiyun.educations.api.collect.mapper;

import com.zhuiyun.educations.api.collect.entity.CollectEntity;
import com.zhuiyun.educations.api.collect.entity.DTO.CollectDTO;
import com.zhuiyun.educations.api.course.entity.Course;
import com.zhuiyun.educations.api.course.entity.DTO.CourseDTO;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName CollectMapper
 * @Description TODO
 * @Author cjl
 * @Date 2023/6/26 9:25
 **/
@Mapper
public interface CollectMapper extends BaseMapper<CollectEntity> {

    /**
    * @Author cjl
    * @Description 查寻登录用户的收藏（视频 文章 直播）
    * @Date 2023/6/26 14:43
    * @Return java.util.List<com.zhuiyun.educations.api.collect.entity.DTO.CollectDTO>
    * @param userId
    * @param type
    */
    @Select("SELECT\n" +
            "\tcourse_info.*,\n" +
            "\tprice.price,\n" +
            "\tteacher.t_name\n" +
            "FROM\n" +
            "\tcourse_info\n" +
            "\tLEFT JOIN price ON course_info.id = price.course_id\n" +
            "\tLEFT JOIN teacher on course_info.teacher_id = teacher.id\n" +
            "\tLEFT JOIN collect ON course_info.id = collect.course_id \n" +
            "WHERE\n" +
            "\tcollect.del_flag = 0 \n" +
            "\tAND course_info.course_status = 0 \n" +
            "\tAND course_info.del_flag = 0 \n" +
            "\tAND course_info.course_type = #{courseType}\n" +
            "\tAND collect.user_id = #{userId}\n" +
            "ORDER BY collect.create_time DESC;")
    List<CollectDTO> selectCollectJoinCourse(Integer userId, Integer courseType);
}
